﻿using System.Collections;
using System.Collections.Generic;

using Dict.DataModel;
namespace Dict.Blo
{
    public class DictTreasureStrengthBlo
    {
        public static TableTreasureStrengthen GetTableTreasureStrengthen(string treasureId)
        {
            return Dict.DictDataManager.Instance.tableTreasureStrengthenDao.GetById(treasureId);
        }

        public static int GetNeedExpToLevel(int quality,int level)
        {
            if(level <= 1)
                return 0;
            List<TableTreasureStrengthLevelExp> list = Dict.DictDataManager.Instance.tableTreasureStrengthLevelExpDao.GetByOneIndex(quality);
            
            return list[level - 2].exp;
        }

        public static int GetTotalNeedExpToLevel(int quality, int level)
        {
            if (level <= 1)
                return 0;
            List<TableTreasureStrengthLevelExp> list = Dict.DictDataManager.Instance.tableTreasureStrengthLevelExpDao.GetByOneIndex(quality);
            int totalexp = 0;
            for (int i = 0; i <= level - 2; i++)
            {
                totalexp += list[i].exp;
            }
            return totalexp;
        }

        public static int GetPredictLevelWithExp(int quality,int curLevel,int exp)
        {
            List<TableTreasureStrengthLevelExp> list = Dict.DictDataManager.Instance.tableTreasureStrengthLevelExpDao.GetByOneIndex(quality);
            int totalExp = exp;
            int predictlv = curLevel;
            for(int i = curLevel - 1; i < list.Count; i++)
            {
                if (totalExp >= list[i].exp)
                {
                    totalExp -= list[i].exp;
                    predictlv = i + 2;
                }
                else
                {
                    break;
                }
            }

            return predictlv;
        }
    }
}
